package com.adaxi.adc.business.vehicletrip.controller;



import com.adaxi.adc.business.vehicletrip.service.TripService;
import com.adaxi.adc.business.vehicletrip.vo.Trip;
import com.adaxi.adc.business.vehicletrip.vo.TripDTO;
import com.adaxi.adc.common.common.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class TripController {
    @Autowired
    TripService tripService;

    @GetMapping("/trips")
    public CommonResult getTrips(
            @RequestParam(name = "page", defaultValue = "1") int page,
            @RequestParam(name = "pageSize", defaultValue = "10") int pageSize
    ) {
        int startRow = (page - 1) * pageSize;
        List<Trip> tripList = tripService.getTripsWithPaging(startRow, pageSize);
        List<TripDTO> tripDTOs = new ArrayList<>();
        for (Trip trip : tripList) {
            tripDTOs.add(new TripDTO(trip));
        }
        return CommonResult.SUCCESS("司机端首页加载分页",tripDTOs);
    }
}
